package com.ccsoft.rsclient;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.ccsoft.rsserver.IProcessInfo;

public class MainActivity extends Activity {
    private static final String TAG = "chanchaw";

    TextView text = null;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        text = findViewById(R.id.rsclient_textview);
    }

    // 绑定远程服务
    public void bindRemoteService(View v){
        Intent intent = new Intent();
        intent.setAction("com.jxx.server.service.bind");//Service的action
        intent.setPackage("com.ccsoft.rsserver");//App A的包名
        bindService(intent, mServerServiceConnection, BIND_AUTO_CREATE);
    }


    ServiceConnection mServerServiceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {

            Log.i(TAG, "MyRemoteService onServiceConnected");
            // 通过aidl取出数据
            IProcessInfo processInfo = IProcessInfo.Stub.asInterface(service);
            try {
                Log.i(TAG, "MyRemoteService process id = " + processInfo.getProcessId());
                text.setText("绑定成功！");
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            Log.i(TAG, "MyRemoteService onServiceDisconnected");
        }
    };


}
